home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 18 / forthsup / linea.fth < prev    next >
Encoding:
Text File  |  1986-09-18  |  5.7 KB  |  216 lines

  1. \ "Line A" Graphics Interface
  2. \ Written by Jesse Taylor.
  3.  
  4. decimal
  5.  
  6. variable a-vars
  7. \ Create a name which will return the address stored in a-vars plus an offset
  8. : afield:  ( offset -- )
  9.    create ,
  10. \ does> @ a-vars @ +
  11.    ;code
  12.    sp )+       a0 lmove
  13.    a0 )        a0 lmove    
  14.    a-vars l#)  a0 adda
  15.    a0       sp -) lmove
  16. c;
  17.  
  18. \ These fields reflect the offsets into the table pointed to by A0 when the
  19. \ line A graphics are first initialized.
  20.  
  21.   0 afield: v_planes
  22.   2 afield: v_lin_wr
  23.   4 afield: contrl
  24.   8 afield: intin
  25.  12 afield: ptsin
  26.  16 afield: intout 
  27.  20 afield: ptsout
  28.  24 afield: _fg_bp_1    
  29.  26 afield: _fg_bp_2
  30.  28 afield: _fg_bp_3
  31.  30 afield: _fg_bp_4
  32.  32 afield: _lstlin
  33.  34 afield: _ln_mask
  34.  36 afield: _wrt_mod
  35.  38 afield: _x1
  36.  40 afield: _y1
  37.  42 afield: _x2
  38.  44 afield: _y2
  39.  46 afield: _patptr
  40.  50 afield: _patmsk
  41.  52 afield: _multifill
  42.  54 afield: _clip
  43.  56 afield: _xmn_clip
  44.  58 afield: _ymn_clip
  45.  60 afield: _xmx_clip
  46.  62 afield: _ymx_clip 
  47.  64 afield: _xacc_dda
  48.  66 afield: _dda_inc
  49.  68 afield: _t_sclsts          
  50.  70 afield: _mono_status
  51.  72 afield: _sourcex
  52.  74 afield: _sourcey
  53.  76 afield: _destx
  54.  78 afield: _desty
  55.  80 afield: _delx
  56.  82 afield: _dely 
  57.  84 afield: _fbase
  58.  86 afield: _fwidth
  59.  90 afield: _style
  60.  92 afield: _litemask
  61.  94 afield: _skewmask
  62.  96 afield: _weight
  63.  98 afield: _r_off
  64. 100 afield: _l_off
  65. 102 afield: _scale
  66. 104 afield: _chup
  67. 106 afield: _text_fg
  68. 108 afield: _scrtchchp
  69. 112 afield: _scrpt2
  70. 114 afield: _text_bg
  71. 116 afield: _copytran
  72.  
  73. -324 afield: mouse-clipped?     \ th 200 bit is off if clipped to the right
  74. -326 afield: mouse-raster     \ mouse offset from beginning of screen mem.
  75.                  \ plus th 8000
  76. -330 afield: mouse-cursor-height \ Height in pixels of the mouse cursor
  77. -340 afield: mouse-moved?     \ Toggles if mouse moves more than threshhold
  78. -342 afield: mouse-y         \ mouse y in pixel coordinates
  79. -344 afield: mouse-x         \ mouse x in pixel coordinates
  80. -348 afield: mouse-buttons     \ mouse button flags
  81.                 \ 8000 - last button was the right one
  82.                 \ 4000 - last button was the left one
  83.                 \ 0200 - right button is down
  84.                 \ 0100 - left button is down
  85.  
  86. \ these are the regular program variables
  87. variable patmskv  7 patmskv !
  88. hex
  89.  
  90. decimal
  91. \ this is a table containing the three resolution modes on the st
  92.  create rez-table   320 w, 200 w,  640 w, 200 w,  640 w, 400 w,
  93.  
  94. hex
  95. : get-rez  ( -- x y )  \ return current screen resolution
  96.    getrez  4 *  rez-table + dup w@ swap 2+ w@ 
  97. ;
  98. code init-a  ( -- addr )  \ line A graphics init routine
  99.    a000 w,
  100.    a0   a-vars l#)  lmove
  101. c;
  102. code put-pix    ( -- )    a001 w,  c;            \ set pixel
  103. code get-pix    ( -- n )  a002 w, d0 sp -) lmove  c;    \ get pixel
  104. code do-line    ( -- )    a003 w,  c;            \ draw line
  105. code h-line     ( -- )    a004 w,  c;            \ horizontal line
  106. code fill-rec   ( -- )    a005 w,  c;            \ filled rectangle
  107. code fill-poly  ( -- )    a006 w,  c;            \ filled polygon
  108. code show-mouse ( -- )    a007 w,  c;            \ show mouse
  109. code hide-mouse ( -- )    a00a w,  c;            \ hide mouse
  110. code transform-mouse  ( -- )  a00b w,  c;    \ transform mouse cursor
  111. code copy-raster ( -- ) a00e w,  c;            \ raster copy
  112.  
  113. \ Draw sprite (a00d) and undraw sprite (a00c) are missing
  114.  
  115. decimal
  116.  
  117. : set-clip  ( x1 y1 x2 y2 --  ) \ set the clipping rectangle
  118.    _ymx_clip  w!   _xmx_clip w!
  119.    _ymn_clip  w!   _xmn_clip w!
  120. ;
  121. : color  ( pl1 pl2 pl3 pl4 -- )  \ set the 4 color planes
  122.    _fg_bp_4 w!  _fg_bp_3 w!   _fg_bp_2 w!  _fg_bp_1 w!
  123. ;
  124. : lmask!  ( n -- )  \ set the line mask variable
  125.    _ln_mask w!
  126. ;
  127. : line-a-init  ( -- )  \ high level line a initialization routine
  128.    init-a
  129.    -1 lmask!
  130.    -1  _lstlin     w!   
  131.    0   _multifill  w!
  132.    1 0 0 0 color
  133.    patmskv @  _patmsk w!
  134.    0 0 640 400 set-clip
  135. ;
  136. : !pix  ( x y value --  ) \ high level pixel setting routine
  137.    intin @  w!
  138.    ptsin @ swap  over 2+ w!  w!
  139.    put-pix
  140. ;
  141. : @pix  ( x y -- value )  \ high level pixel fetching
  142.    ptsin @  swap over 2+  w!  w!  get-pix
  143. ;
  144. : draw  ( x1 y1 x2 y2 -- )  \ high level line routine
  145.    _y2 w!   _x2 w!    _y1 w!   _x1 w!
  146.    do-line
  147. ;
  148.  
  149. : rectangle ( x1 y1 x2 y2 --  )  \ draw a filled rectangle
  150.    _y2 w!   _x2 w!    _y1 w!   _x1 w!
  151.    fill-rec
  152. ;
  153. decimal
  154.  
  155. : poly-line  ( addr n --  )  \ draw a line polygon
  156.    4* over + swap
  157.    do   i w@  i 2+ w@  i 4 + w@  i 6 + w@  draw   4 +loop
  158. ;
  159.  
  160. code polygon  ( y1 y2 addr n --  )  \ fast polygon inner loop
  161.    sp )+          d0          lmove
  162.    a-vars l#)     a1          lmove   
  163.    ' contrl >body @  a1 d)    a2          lmove 
  164.    d0             2 a2 d)     wmove
  165.    ' ptsin >body @  a1 d)     d7          lmove
  166.    sp )+    ' ptsin >body @  a1 d)    lmove 
  167.    sp )+          d6          lmove
  168.    sp )+          d5          lmove
  169.    a3             sp -)       lmove   \ Save a3
  170.    a1             a3          lmove   \ a1 gets clobbered so we use a3
  171.    d5             d6          sub
  172.    begin
  173.     d5 ' _y1 >body @  a3 d) wmove
  174.     hex a006 w, decimal
  175.     1 d5 addq
  176.    d6 dbra
  177.    d7  ' ptsin >body @  a3 d) lmove
  178.    sp )+          a3          lmove
  179. c;
  180.  
  181. \ this is an example of the use of the polygon routine
  182. \ create poly1
  183. \        100 w, 100 w,    100 w, 200 w,
  184. \        1   w, 300 w,    600 w, 250 w,
  185. \        200 w, 375 w,    100 w, 100 w,
  186. \ : polytest
  187. \  poly1 5  poly-line
  188. \ ;
  189.  
  190. 2 xbios: physbase { -- a.screen-base }
  191. physbase constant scradr
  192.  
  193. decimal
  194. create mfdb
  195.    scradr ,
  196.    \ I'm not sure the next line is right
  197.    getrez dup  4*  rez-table + dup w@ swap @ ,
  198.    16 / w,
  199.    0 w,
  200.    2* 1 max 4 swap - 1 max  w,
  201.    0 w,
  202.    0 ,
  203.  
  204.  
  205. \ rasmove (raster copy) is a fast low level bit map move routine
  206.  
  207. decimal
  208.  
  209. : rasmove  ( sx1 sy1 sx1 sx2 dx1 dy1 dx2 dy2 m -- )
  210.    mfdb dup  contrl @  14 + 2!
  211.    intin @  w!
  212.    ptsin @  dup 14 +
  213.     do  i w!  -2 +loop
  214.    copy-raster
  215. ;
  216.